<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys,
                 com.actimind.actitime.util.Capsule,
                 com.actimind.actitime.resources.UserResource,
                 com.actimind.actitime.beans.CustomerBean,
                 java.util.Iterator,
                 com.actimind.actitime.resources.CustomerResource,
                 java.sql.Connection,
                 java.util.List,
                 com.actimind.actitime.util.Util,
                 org.apache.struts.util.ResponseUtils"%><%@ page errorPage="/error.jsp" %><%

UserBean loggedInUser = (UserBean)session.getAttribute(Keys.LOGGEDIN_USER_KEY);
if (loggedInUser != null)
{
    Capsule c = new Capsule(null);

    try
    {
        UserResource ur = new UserResource();
        CustomerResource cr = new CustomerResource();

        Connection con = c.getConnection();

        if (loggedInUser.isRoot() || ur.hasUserRight(con, loggedInUser.getId(), "tasks.manage_customers"))
        {
            List customersList  = cr.getAllCustomers(con);

%>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Customers</title>

    <script language="JavaScript" src="../js/at.js"></script>

    <link rel="stylesheet" href="../css/at.css" type="text/css">
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="project" />
    <jsp:param name="pageAction" value="customerlist" />
</jsp:include>

<form>
<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff">
<tr>
    <td class="pagetitle">
        Customers
    </td>
    <td align="right">
        <input type="button" value="Add New Customer" onclick="javascript:document.location.href='<html:rewrite href='customeradd.do'/>'" />
    </td>
</tr>
<tr>
    <td colspan="2" class="pagetitle">
        <at:errors />
        <at:messages id="message" message="true">
            <span class="successmsg"><bean:write name="message"/></span>
        </at:messages>
    </td>
</tr>
<tr>
    <td colspan="2">
        <table border="0" cellspacing="1" cellpadding="5"  align="center" width="770">
        <tr>
            <th class="listtblcolheader">Customer</th>
            <th class="listtblcolheader" width="13%">Billing Status</th>
            <th class="listtblcolheader" width="20%">Customer Description</th>
        </tr>
<%
            Iterator it = customersList.iterator();

            CustomerBean customer = null;

            while (it.hasNext())
            {
                customer = (CustomerBean)it.next();

%>
        <tr>
              <td align="center" class="listtblcell"><html:link href='<%="customeredit.do?customerId=" + customer.getId()%>'><%=ResponseUtils.filter(customer.getName())%></html:link></td>
<%
                if (customer.isBillingStatus())
                {
%>            <td align="center" class="listtblcell">Billable</td>
<%
                }
                else
                {
%>            <td align="center" class="listtblcell">Non-Billable</td>
<%
                }
%>
<%
                if (!Util.isEmpty(customer.getDescription()))
                {
%>            <td align="center" class="listtblcell"><a href="javascript:popup('<html:rewrite href='<%="customerdetails.do?customerId=" + customer.getId()%>'/>', 'popup', 758, 248, false, false, false);"><img src="../img/note.gif" width="14" height="16" border="0" hspace="0" vspace="0"></a></td>
<%
                }
                else
                {
%>            <td align="center" class="listtblcell"><img src="../img/note_empty.gif" width="14" height="16" hspace="0" vspace="0"></td>
<%
                }
%>
        </tr>
<%
            }
%>
        </table>
    </td>
</tr>
</table>
</form>

</body>
</html>
<%
        }
        else
        {
            response.sendRedirect("../login.do");
        }
    }
    finally
    {
        if (c != null)
            c.cleanup();
    }
}
else
{
    response.sendRedirect("../login.do");
}
%>